package com.example.homelicaisystem.control;

import com.example.homelicaisystem.entity.DTO.InvestmentDTO;
import com.example.homelicaisystem.entity.Investment;
import com.example.homelicaisystem.entity.ListWithCount;
import com.example.homelicaisystem.entity.MyAsset;
import com.example.homelicaisystem.entity.User;
import com.example.homelicaisystem.services.MyAssetService;
import com.example.homelicaisystem.utils.HandleMoney;
import com.example.homelicaisystem.utils.Result;
import jdk.internal.org.objectweb.asm.Handle;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/myAsset")
@RestController
@Slf4j
public class MyAssetControl {
    private final MyAssetService myAssetService;

    public MyAssetControl(MyAssetService myAssetService) {
        this.myAssetService = myAssetService;
    }


    @GetMapping("/listCard")
    public Result<List<MyAsset>> getListCard() {
        log.debug("收到请求list请求。");

        List<MyAsset> list = myAssetService.getListCard();
        list.forEach(myAsset -> {
            myAsset.setAlipay(HandleMoney.showMoney(myAsset.getAlipay()));
            myAsset.setWeichat(HandleMoney.showMoney(myAsset.getWeichat()));
            myAsset.setMoney(HandleMoney.showMoney(myAsset.getMoney()));
        });
        return Result.ok(list);
    }

    @GetMapping("/listInvestment")
    public Result<List<Investment>> getListInvestment() {
        log.debug("收到请求list请求。");
        return Result.ok(myAssetService.getListInvestment());
    }
}

